using System.Collections.Generic;

namespace Monopoly
{
    public class MGame
    {
        int _maxRoundNumber;
        int _playerNumber;
        int _currentRoundNumber;
        Board _board;
        List<Player> _players;
        List<Die> _dice = new List<Die>(Player.TOTAL_DICE);

        public int PlayerNumber 
        {
            get { return _playerNumber; } 
            set { _playerNumber = value; } 
        }

        public int RoundTotal 
        { 
            get { return _maxRoundNumber; } 
            set { _maxRoundNumber = value; } 
        }

        public int CurrentRoundNumber { get { return _currentRoundNumber; } }

        internal Board Board { get { return _board; } }
        public List<Player> Players { get { return _players; } }

        public void NewGame()
        {
            _currentRoundNumber = 0;
            _board = new Board();
            _players = new List<Player>();
            for (int i = 0; i < Player.TOTAL_DICE; i++)
            {
                _dice.Add(new Die());
            }
            InitPlayer();
        }

        public void Play()
        {
            for (int i = 0; i < _maxRoundNumber; i++)
            {
                PlayRound();
            }
        }

        public void PlayRound()
        {
            foreach (var player in _players)
            {
                player.TakeTurn();
               
            }
            _currentRoundNumber++;
        }

        private void InitPlayer()
        {
            for (int i = 1; i <= _playerNumber; i++)
            {
                var player = new Player("player" + i.ToString(), _board, _dice);
                _players.Add(player);
            }
        }
    }
}